Microsoft® Visual Basic® Scripting Edition
How VBScript Looks in HTML
VBScript Tutorial |
Previous | Next |

 

The <SCRIPT> Tag
VBScript code goes on an HTML page inside paired <SCRIPT> tags. For example, a procedure to test a delivery date might appear as follows:

<SCRIPT LANGUAGE="VBScript"> 
<!--
   Function CanDeliver(Dt)
      CanDeliver = (CDate(Dt) - Now()) > 2
   End Function
-->
</SCRIPT>

Beginning and ending <SCRIPT> tags surround the code. Notice that the LANGUAGE attribute indicates the scripting language. You must specify the language because Microsoft Internet Explorer version 3.0 can use other scripting languages. In addition, notice that the CanDeliver function is embedded in comment tags (<!-- and -->). This prevents browsers that don't understand the <SCRIPT> tag from displaying the code.

Since the example is a general function—it isn't tied to any particular form control—you can include it in the HEAD section of the page:


<HTML>
<HEAD>
<TITLE>Place Your Order</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!--
   Function CanDeliver(Dt)
      CanDeliver = (CDate(Dt) - Now()) > 2
   End Function
-->
</SCRIPT>
</HEAD>
<BODY>
...

You can use procedures in code anywhere in a page. You can put procedures in both the BODY and HEAD sections. However, you may want to put all procedures in the HEAD section in order to keep all the code together.


© 1997 Microsoft Corporation. All rights reserved. Legal Notices.